Repository navigation
fix: harden DOM-XSS surfaces flagged by CodeQL js/xss - #143
Merged
Merged
Conversation
therealsama
force-pushed
the
feat/harden-xss-codeql-alerts
branch
from
June 10, 2026 07:59
3a19eba to
9ea80e4
Compare
therealsama
enabled auto-merge
June 10, 2026 08:08
Sanitize untrusted HTML before it is parsed into a DOM in sanitizeHtml:
input now passes through DOMPurify before any innerHTML write instead of
only sanitizing the output, and the instance is renamed to the canonical
`DOMPurify`. The template write was already inert, so this is defense in
depth that also clears CodeQL's recognized barrier.
Only render http(s) URLs as outbound anchors in ItemArticle and StoryCard:
a hostile `javascript:`/`data:` URL from the HN API can no longer reach an
anchor href (React blocks `javascript:` but not `data:`). Non-http(s) URLs
degrade to the plain-text title / in-app discussion link.
The scheme check guards a single local `rawUrl` binding with one
`startsWith('http')`. That shape is required for CodeQL to honor the
barrier: a `||` of two checks reopens the finding because a LogOrExpr
doesn't carry the guard's true outcome into the guarded branch.
Add regression tests for the URL-scheme guard.
therealsama
force-pushed
the
feat/harden-xss-codeql-alerts
branch
from
June 10, 2026 08:10
9ea80e4 to
a65abb5
Compare
kplachkov
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sanitize untrusted HTML before it is parsed into a DOM in sanitizeHtml:
input now passes through DOMPurify before any innerHTML write instead of
only sanitizing the output, and the instance is renamed to the canonical
DOMPurify. The template write was already inert, so this is defense indepth that also clears CodeQL's recognized barrier.
Only render http(s) URLs as outbound anchors in ItemArticle and StoryCard:
a hostile
javascript:/data:URL from the HN API can no longer reach ananchor href (React blocks
javascript:but notdata:). Non-http(s) URLsdegrade to the plain-text title / in-app discussion link.
The scheme check guards a single local
rawUrlbinding with onestartsWith('http'). That shape is required for CodeQL to honor thebarrier: a
||of two checks reopens the finding because a LogOrExprdoesn't carry the guard's true outcome into the guarded branch.
Add regression tests for the URL-scheme guard.